package com.sample.service.scheduling;

import com.sample.service.EventMetadata;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.JobDetailBean;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.text.SimpleDateFormat;
import java.util.Map;

/**
 * User: khanhpham
 * Date: 10/26/11
 */
public class SimpleJob extends QuartzJobBean {

   @Override
   protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
      final SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
      JobDetailBean jobDetail = (JobDetailBean) jobExecutionContext.getJobDetail();
      Map<String, Object> data = jobDetail.getJobDataMap();
      EventMetadata eventMetadata = (EventMetadata) data.get("EVENT_METADATA");
      System.out.println("Hello. Your job has been kicked off");
      System.out.println("Process Name: " + eventMetadata.getProcessName());
      System.out.println("Process Type: " + eventMetadata.getProcessType());
      System.out.println("Process Date: " + sdf.format(eventMetadata.getStartDate()));
   }
}
